﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using BussinesLogic;
using System.Collections;

namespace DataAccess.Factory
{
    class PortadaFactoryDao : BaseFactory
    {

        public PortadaFactoryDao()
        {
            this.classType = typeof(Portada);
        }

        private string uspGetPortadabyExpediente = @"fd_Portada_get_by_Expediente";
        private string uspGetPortadabyDocumento = @"fd_Portada_get_by_Documento";
        private string uspGetPortadabyId = @"fd_Portada_get_by_ExpedienteId";
        private string uspCreatePortada = @"fd_Portada_Create";
        private string uspUpdatePortada = @"fd_Portada_Update";

        /* funciones */

        public Portada getPortadabyExpediente(string NoExpediente)
        {
            SqlParameter [] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@NoExpediente", NoExpediente);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetPortadabyExpediente);

            if (obj != null && obj.Count > 0)
            {
                return (Portada)obj[0];
            }
            else
            {
                return null;
            }
            
        }
        public Portada getPortadabyDocumento(string CodDocumento)
        {
            SqlParameter[] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@CodDocumento", CodDocumento);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetPortadabyDocumento);

            if (obj != null && obj.Count > 0)
            {
                return (Portada)obj[0];
            }
            else
            {
                return null;
            }
        }

        public Portada getPortadabyId(int Id)
        {
            SqlParameter[] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@Id", Id);

            ArrayList obj = this.DataTableToObjectList(parameter, this.uspGetPortadabyId);

            if (obj != null && obj.Count > 0)
            {
                return (Portada)obj[0];
            }
            else
            {
                return null;
            }
        }

        public int createPortada(string xmlUser)
        {
            SqlParameter[] parameter = new SqlParameter[2];

            parameter[0] = new SqlParameter("@portada", xmlUser);
            parameter[1] = new SqlParameter("@ID", SqlDbType.Int);
            parameter[1].Direction = ParameterDirection.Output;

            this.executeNoQuery(parameter, this.uspCreatePortada);

            return (int)parameter[1].Value;
        }
        public int updatePortada(string xmlUser)
        {
            SqlParameter[] parameter = new SqlParameter[1];

            parameter[0] = new SqlParameter("@portada", xmlUser);
            
            this.executeNoQuery(parameter, this.uspUpdatePortada);

            return (int)parameter[1].Value;
        }
    }
}
